package everyday.leetcode;

/**
 * @Author: wenjingyuan
 * @Date: 2022/10/11/21:09
 * @Description:仅执行一次字符串交换能否使两个字符串相等
 * https://leetcode.cn/problems/check-if-one-string-swap-can-make-strings-equal/
 */
public class Num1790 {
    public boolean areAlmostEqual(String s1, String s2) {
        int cnt=0;
        char c1=0;char c2=0;
        for (int i = 0; i < s1.length(); i++) {
            char a=s1.charAt(i);
            char b=s2.charAt(i);
           if(a!=b){
               cnt++;
               if(cnt>2 || (cnt==2 && (a!=c2 || b!=c1))){
                   return false;
               }
               c1=a;
               c2=b;
           }
        }
        return cnt==2 || cnt==0;
    }
}
